#ifndef COMM_PROTOCOL_H
#define COMM_PROTOCOL_H

#include "stdint.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef enum CommProtocolError {
    Error_None = 0,
    Error_UnknownFormat = 1,
    Error_Illegal = 2,
    Error_CRCFailed = 3,
};

typedef struct CommProtocolPortable {
    int (*authenticate)(char *password);
    uint16_t (*randKey)();
    int (*sendResponse)(void *buffer,int size);
    int (*readData)(int index,void *buffer,int *size);
    int (*writeData)(int index,void *buffer,int size);
    int (*writeOTAData)(uint32_t address_offset,void *buffer,int size);
    int (*startOTA)(void);
} CommProtocolPortable_t;

void CommProtocol_init(CommProtocolPortable_t *portable);
int CommProtocol_parseRequest(void *buffer);
void CommProtocol_loop();

#ifdef __cplusplus
}
#endif

#endif
